package field_method01;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StudentManagementSystem {

    private static List<Student> students = new ArrayList<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("1. 添加学生");
            System.out.println("2. 显示所有学生");
            System.out.println("3. 退出");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    addStudent(scanner);
                    break;
                case 2:
                    displayAllStudents();
                    break;
                case 3:
                    return;
                default:
                    System.out.println("无效选择");
            }
        }
    }

    private static void addStudent(Scanner scanner) {
        System.out.println("输入学生姓名：");
        String name = scanner.next();

        System.out.println("输入学生年龄：");
        int age = scanner.nextInt();

        Student student = new Student(name, age);
        students.add(student);
    }

    private static void displayAllStudents() {
        for (Student student : students) {
            System.out.println("姓名：" + student.getName() + ", 年龄：" + student.getAge());
        }
    }

    static class Student {
        private String name;
        private int age;

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }
    }
}